package com.nuoniu.sibanyun.controller.production;


import com.nuoniu.sibanyun.common.exception.NuoNiuException;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.dto.VProductionWorkMainSplitDto;
import com.nuoniu.sibanyun.entity.production.ErpWorkProcedureCardMain;
import com.nuoniu.sibanyun.entity.production.VProductionWorkMain;
import com.nuoniu.sibanyun.service.production.IErpWorkProcedureCardMainService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.nuoniu.sibanyun.common.BaseController;

/**
 * <p>
 * 工序流转卡主表 前端控制器
 * </p>
 *
 * @author 白强
 * @since 2021-03-30
 */
@RestController
@RequestMapping("/erp/workProcedureCardMain")
@Api(tags = "工序流转卡主表")
public class ErpWorkProcedureCardMainController extends BaseController {

    @Autowired
    private IErpWorkProcedureCardMainService erpWorkProcedureCardMainService;

    @ApiOperation("获取单据编码")
    @GetMapping("getCode")
    public HttpResult getCode() {
        return HttpResult.ok(erpWorkProcedureCardMainService.getCode());
    }

    @ApiOperation("保存")
    @PostMapping("save")
    public HttpResult save(@RequestBody ErpWorkProcedureCardMain erpWorkProcedureCardMain) {
        erpWorkProcedureCardMainService.saveOrder(erpWorkProcedureCardMain);
        return HttpResult.ok();
    }



    /**
     * 提交
     */
    @GetMapping("submit")
    @ApiOperation("单据提交")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "单据id"),
            @ApiImplicitParam(name = "status", value = "状态 0:提交,-1:反提交")
    })
    public HttpResult submit(Long id, Integer status) {
        erpWorkProcedureCardMainService.submit(id, status);
        return HttpResult.ok();
    }
    /**
     * 审核/弃审
     * @author 小啊刚
     * @date 2020-11-25
     */
    @GetMapping("examine")
    @ApiOperation("单据审核")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "单据id"),
            @ApiImplicitParam(name = "status", value = "状态 0:审核,1:已审")
    })
    public HttpResult examine(Long id, Integer status) {
        if (null == status || status < 0 || status > 1)
            throw new NuoNiuException("状态参数错误");
        erpWorkProcedureCardMainService.examine(id,status);
        return HttpResult.ok();
    }

    @ApiOperation("删除单据")
    @DeleteMapping("delete")
    public HttpResult delete(Long id) {
        erpWorkProcedureCardMainService.delete(id);
        return HttpResult.ok();
    }

}
